package 测试;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

public class JavaTest {

	public static void main(String[] args) {

		HashMap<String, Integer> hm = new HashMap<String, Integer>();
		hm.put("zhang", 20);
		hm.put("wang", 50);
		hm.put("Lee", 80);

		ArrayList<Map.Entry<String, Integer>> al = new ArrayList<>(hm.entrySet());
		System.out.println(al.toString());

		Collections.sort(al, new Comparator<Map.Entry<String, Integer>>() {

			@Override
			public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2) {
				Integer x1 = o1.getValue();
				Integer x2 = o2.getValue();
				return x1 < x2 ? 1 : -1;
			}
		});

		System.out.println(al.toString());

		Collections.sort(al, (Entry<String, Integer> o1, Entry<String, Integer> o2) -> {
			return o1.getValue() < o2.getValue() ? -1 : 1;
		});

		System.out.println(al.toString());

	}

}
